from django.db import models
from common.db import BaseModel
# Create your models here.
class Order(BaseModel):
    """订单表"""
    ORDER_STATUS=(
        (1,'待支付'),
        (2, '待发货'),
        (3, '配送中'),
        (4, '待评价'),
        (5, '已完成'),
        (6, '已关闭'),
    )
    PAY_TYPES=(
        (1,'支付宝'),
        (2, '银联'),
        (3, '信用卡'),
        (4,'货到付款')
    )
    user=models.ForeignKey('user.User',on_delete=models.CASCADE,verbose_name='下单用户')
    addr=models.CharField(verbose_name='收货地址',max_length=200)
    order_code=models.CharField(verbose_name='订单编号',max_length=50)
    amount=models.FloatField(verbose_name='订单总金额')
    status=models.SmallIntegerField(verbose_name='订单状态',default=1,choices=ORDER_STATUS)
    pay_type=models.SmallIntegerField(verbose_name='支付方式',choices=PAY_TYPES,default=1)
    pay_time=models.DateTimeField(verbose_name='支付时间',blank=True,null=True)
    trade_no=models.CharField(verbose_name='支付单号',blank=True,max_length=50,null=True)

    class Meta:
        db_table = 'order'
        verbose_name = '订单表'
        verbose_name_plural = verbose_name

class OrderGoods(BaseModel):
    """订单商品表"""
    order=models.ForeignKey('Order',verbose_name='所属订单',on_delete=models.CASCADE)
    goods=models.ForeignKey('goods.Goods',verbose_name='商品ID',on_delete=models.CASCADE)
    price=models.IntegerField(verbose_name='商品价格')
    number=models.IntegerField(verbose_name='商品数量',default=1)

    class Meta:
        db_table = 'orderGoods'
        verbose_name = '订单商品表'
        verbose_name_plural = verbose_name

class Comment(BaseModel):
    """订单评论表"""
    RATES=(
        (1,'好评'),
        (2, '中评'),
        (3, '差评')
    )
    STARS=(
        (1,'一星'),
        (2, '二星'),
        (3, '三星'),
        (4, '四星'),
        (5, '五星')
    )
    user=models.ForeignKey('user.User',on_delete=models.CASCADE)
    order=models.ForeignKey('Order',on_delete=models.CASCADE)
    goods=models.ForeignKey('goods.Goods',on_delete=models.CASCADE)
    content=models.CharField(verbose_name='评论内容',default='',max_length=500)
    rate=models.SmallIntegerField(verbose_name='评论级别',default=1,choices=RATES,blank=True)
    star=models.SmallIntegerField(verbose_name='评论星级',default=5,choices=STARS,blank=True)
    class Meta:
        db_table = 'comment'
        verbose_name = '评论表'
        verbose_name_plural = verbose_name


